package com.xm.controller;

import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
import com.xm.entity.User;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UserController {

    @PostMapping
    @LogRecord(type = "系统用户",
            subType = "创建用户",
            bizNo = "{{#userInfo.id}}",
            success = "创建了用户【{{#userInfo.name}}】",
            fail = "创建了用户【{{#userInfo.name}}】失败了，失败原因：「{{#_errorMsg}}」",
            operator = "张三")
    public User createUser(@RequestBody User user) {
        // 这里是业务操作
        LogRecordContext.putVariable("userInfo", user);
        return user;
    }

}
